//
//  RHDeviceTopoCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/4.
//

#import "RHDeviceTopoCell.h"
#import "RHDeviceTopoHEBATView.h"
#import "RHDeviceTopoHEBATParallelView.h"
#import "RHDeviceTopoMEView.h"
#import "RHDeviceTopoME_61View.h"
#import "RHDeviceTopoME_215EUView.h"

 NSString *const DevTopoCellHEBat = @"DevTopoCellHEBat";
 NSString *const DevTopoCellHEBat_Parallel = @"DevTopoCellHEBat_Parallel";
 NSString *const DevTopoCellME    = @"DevTopoCellME";
 NSString *const DevTopoCellME_61          = @"DevTopoCellME_61";//61kWh

@interface RHDeviceTopoCell ()

@property (nonatomic, strong) NSDictionary *dic;

//设备能量流向
@property (nonatomic ,strong) RHTopoModel *topoModel;

@property (nonatomic ,strong) RHDeviceModel *deviceModel;
//HE_BAT
@property (nonatomic, strong) RHDeviceTopoHEBATView *HE_BATView;
//HE_BAT 并机
@property (nonatomic, strong) RHDeviceTopoHEBATParallelView *HE_BATParallelView;

@property (nonatomic, strong) RHDeviceTopoMEView *MEView;

@property (nonatomic, strong) RHDeviceTopoME_61View *ME_61View;

@property (nonatomic, strong) RHDeviceTopoME_215EUView *ME_215EUView;
@end
@implementation RHDeviceTopoCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    _HE_BATView.dic = dic;
}

-(void)setTopoModel:(RHTopoModel *)topoModel deviceModel:(nonnull RHDeviceModel *)deviceModel
{
    _topoModel = topoModel;
    _deviceModel = deviceModel;
    if (deviceModel.productTypeId == ProductType_HE_BAT||deviceModel.productTypeId == ProductType_HE_ALLINONE) {
        [_HE_BATView setTopoModel:topoModel deviceModel:deviceModel];
        [_HE_BATParallelView setTopoModel:topoModel deviceModel:deviceModel];
    }
    //微网的没有并机
    if ([deviceModel.deviceTypeCode is61DeviceType]) {
        [_HE_BATParallelView setTopoModel:topoModel deviceModel:deviceModel];
    }
    
    
}

-(void)set233TopoModel:(RH233TopoModel*)topoModel deviceModel:(RHDeviceModel*)deviceModel;
{
    [_MEView setTopo233Model:topoModel];
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = CFTabViewBgColor;
    
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView rounded:8 width:1 color:kBorderColor];
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
//        make.height.offset(kUI_WINDOW_W*0.58+30+60);
    }];

    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = @"能量流向".rh_localized;
    titleLab.textColor = kCOLOR_HEX(@"#171A1D");
    titleLab.textAlignment = NSTextAlignmentRight;
    titleLab.font = kBOLDSYSTEMFONT(16);
    [bgView addSubview:titleLab];
    [titleLab sizeToFit];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.left.mas_offset(15);
        make.height.offset(titleLab.height+1);
    }];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX_A(@"#7E868E",0.16);
    [bgView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(titleLab.mas_bottom).offset(15);
        make.height.offset(1);
    }];
    
    if([self.reuseIdentifier isEqualToString:DevTopoCellHEBat]){
        _HE_BATView = [[RHDeviceTopoHEBATView alloc]init];
        _HE_BATView.layer.cornerRadius = 8;
        _HE_BATView.layer.masksToBounds = YES;
        [bgView addSubview:_HE_BATView];
        [_HE_BATView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(10);
            make.right.mas_offset(-10);
            make.top.equalTo(line.mas_bottom).offset(10);
            make.bottom.mas_offset(-10);
            make.height.offset(250);
        }];
    }else if([self.reuseIdentifier isEqualToString:DevTopoCellME]){
        _MEView = [[RHDeviceTopoMEView alloc]init];
        [bgView addSubview:_MEView];
        [_MEView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.equalTo(line.mas_bottom).offset(10);
        }];
        
    }else if ([self.reuseIdentifier isEqualToString:DevTopoCellHEBat_Parallel]){//并机
        _HE_BATParallelView = [[RHDeviceTopoHEBATParallelView alloc]init];
        _HE_BATParallelView.layer.cornerRadius = 8;
        _HE_BATParallelView.layer.masksToBounds = YES;
        [bgView addSubview:_HE_BATParallelView];
        [_HE_BATParallelView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(10);
            make.right.mas_offset(-10);
            make.top.equalTo(line.mas_bottom).offset(10);
            make.bottom.mas_offset(-10);
            make.height.offset(310);
        }];
    }
    
    QMUIButton *fullBtn = [[QMUIButton alloc]init];
    [fullBtn setImage:[UIImage imageNamed:@"kwt_full_screen"] forState:UIControlStateNormal];
    [bgView addSubview:fullBtn];
    [fullBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(35);
        make.top.equalTo(line.mas_bottom).offset(8);
        make.right.mas_offset(-5);
    }];
    if ([self.reuseIdentifier isEqualToString:DevTopoCellME]) {
        [fullBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(35);
            make.centerY.equalTo(titleLab);
            make.right.mas_offset(-5);
        }];
    }
    
    [[fullBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.fullScreenAction){
            weakSelf.fullScreenAction();
        }
    }];
}


@end
